/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Kuba
 */
public class Rectangle {

    private double zoom = 10e6;// pixel ->nm
    private double z = 100; //nm
    private double lambda = 530; //nm
    private double exposition = 20.0; //x
    private double apertureWidth = 15*lambda; //nm
    private double apertureHeight = 6*lambda; //nm

    Rectangle(double lambda, double exposition, double apertureWidth, double apertureHeight, double z) {
        this.lambda = lambda;
        this.exposition = exposition;
        this.apertureWidth = apertureWidth;
        this.apertureHeight = apertureHeight;
        this.z = z;
    }



    public double getIntensity(int ix, int iy) {

        double x = ix*zoom;
        double y = iy * zoom;
        double s0 = Math.sqrt(z * z + x * x + y * y);
        double nx = x / s0;
        double ny = y / s0;

        double coefx = (Math.PI * apertureWidth *nx) / lambda;
        double coefy = (Math.PI * apertureHeight *ny) / lambda;

        //exposition =  Math.sqrt(Math.pow((Math.sin(2*Math.PI*s0/lambda)/lambda*s0), 2)+Math.pow((Math.cos(2*Math.PI*s0/lambda)/lambda*(-s0)), 2));
        //double c = Math.pow(2*Math.PI/(2*Math.PI), 2);
        double amp =  exposition * (Math.pow(Math.sin(coefx), 2) / (coefx*coefx)) * (Math.pow(Math.sin(coefy), 2) / (coefy*coefy));
        //double amp =  exposition * (Math.sin(coefx) / coefx) * (Math.sin(coefy) / coefy);

        if (amp >= 1.0)
            return 1.0;
        else if (amp <= 0.0)
            return 0.0;
        else
            return amp;
    }

    public void setApertureHeight(double apertureHeight) {
        this.apertureHeight = apertureHeight;
    }

    public void setApertureWidth(double apertureWidth) {
        this.apertureWidth = apertureWidth;
    }

    public void setExposition(double exposition) {
        this.exposition = exposition;
    }

    public void setLambda(double lambda) {
        this.lambda = lambda;
    }

    public void setZ(double z) {
        this.z = z;
    }

    public void setZoom(double zoom) {
        this.zoom = zoom;
    }


    


}
